package cn.stylefeng.guns.modular.api.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.ums.model.params.ShareLogParam;
import cn.stylefeng.guns.modular.ums.model.result.ShareLogResult;
import cn.stylefeng.guns.modular.ums.service.ShareLogService;
import cn.stylefeng.guns.modular.wms.model.params.CollectParam;
import cn.stylefeng.guns.modular.wms.model.result.CollectResult;
import cn.stylefeng.guns.modular.wms.service.CollectService;
import cn.stylefeng.guns.utils.MemberTokenUtil;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 *分享模块管理
 */
@Controller
@RequestMapping("/api/share")
@Api(tags = "分享模块管理")
public class ApiShareController extends BaseController {

    @Autowired
    private ShareLogService shareLogService;

    /**
     * 查询分享列表
     */
    @ResponseBody
    @RequestMapping(value = "/getShareList",method = RequestMethod.GET)
    @ApiOperation(value = "查询分享列表", notes = "查询分享列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "页码", dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name = "limit", value = "每页数量", dataType = "Integer", paramType = "query")
    })
    public ResponseData getTaskList(ShareLogParam param) {
        long memberId=MemberTokenUtil.getMemberId();
        param.setMemberId(memberId);
        LayuiPageInfo pageInfo= shareLogService.findPageBySpec(param);
        return ResponseData.success(pageInfo);
    }

    /**
     * 查询分享详情
     */
    @ResponseBody
    @RequestMapping(value = "/getShareDetail",method = RequestMethod.GET)
    @ApiOperation(value = "查询分享详情", notes = "查询分享详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", required = true, paramType = "query")
    })
    public ResponseData getShareDetail(Long id) {
        ShareLogParam param1=new ShareLogParam();
        param1.setId(id);
        ShareLogResult result=shareLogService.findBySpec(param1);
        return ResponseData.success(result);
    }

    /**
     * 添加/更新分享
     */
    @ResponseBody
    @RequestMapping(value = "/addOrUpdateShare",method = RequestMethod.POST)
    @ApiOperation(value = "添加/更新分享", notes = "添加/更新分享")
    public ResponseData addOrUpdateShare(@RequestBody ShareLogParam param) {
        try {
            long memberId=MemberTokenUtil.getMemberId();
            param.setMemberId(memberId);
            shareLogService.update(param);
            return ResponseData.success();
        }catch (Exception e){
            return ResponseData.error(e.getMessage());
        }
    }

    /**
     * 删除分享
     */
    @ResponseBody
    @RequestMapping(value = "/deleteShare",method = RequestMethod.POST)
    @ApiOperation(value = "删除分享", notes = "删除分享")
    public ResponseData deleteShare(@RequestBody ShareLogParam param) {
        try {
            shareLogService.removeById(param.getId());
            return ResponseData.success();
        }catch (Exception e){
            return ResponseData.error(e.getMessage());
        }
    }

}



